#ifndef POSTSTYLE_H
#define POSTSTYLE_H

#include <QColor>
#include <QImage>
#include <QFont>
#include <QObject>
#include <QSharedPointer>
#include <QByteArray>
#include <QTemporaryFile>
#include "network/httpconnector.h"
#include "network/request.h"
#include "misc.h"

using namespace Wishmaster;
class WISHMASTER_EXPORT PostStyle : public QObject
{
	Q_OBJECT
public:
	PostStyle();
	virtual ~PostStyle();

	bool loadStyle(const QString& style);
	bool loadFromFile(const QString& filename);

	QColor backgroundColor();
	QColor headerColor();
	QColor postBackgroundColor();
	QColor postBorderColor();
	QColor postSelectedBorderColor();
	QColor textColor();
	QColor linkColor();
	QColor linkHoverColor();

	QImage deleteIcon();
	QImage hideIcon();
	QImage unhideIcon();
	QImage infoIcon();

	void setPostFont(const QFont& f);
	QFont postFont();

	void setHeaderFont(const QFont& f);
	QFont headerFont();

	void setNoteFont(const QFont& f);
	QFont noteFont();

	int borderRadius() const;

	QString background() const;
protected:
	QString getSection(const QString& doc, const QString& tag);
	QString getParam(const QString& section, const QString& param);
	QColor parseColor(const QString& color);
	void setColorIfValid(QColor& color, const QColor& newColor);
	void loadBackground(const QString& background);

	void loadDefaults();

protected slots:
	void backgroundImage(RequestPtr r, const QByteArray& arr);

private:
	QColor m_backgroundColor;
	QColor m_headerColor;
	QColor m_postBackgroundColor;
	QColor m_postBorderColor;
	QColor m_postSelectedBorderColor;
	QColor m_textColor;
	QColor m_linkColor;
	QColor m_linkHoverColor;

	QImage m_deleteIcon;
	QImage m_hideIcon;
	QImage m_unhideIcon;
	QImage m_infoIcon;

	QFont m_postFont;
	QFont m_headerFont;
	QFont m_noteFont;

	int m_borderRadius;

	QString m_background;
	QString m_filename;
	QTemporaryFile* m_backgroundFile;

	Connector* m_connector;
};

typedef QSharedPointer<PostStyle> PostStylePtr;

#endif // POSTSTYLE_H

